<template>
  <div class="app-container">
    <div class="change">
      <p>
        <span>发票号</span>
        <el-input v-model="tempData.fapiaohao" class="userselect" type="text" placeholder="请输入发票号"/>
      </p>
      <p>
        <span>发货日期</span>
        <el-input v-model="tempData.fahuotime" class="userselect" type="text" placeholder="请输入发货日期" />
      </p>
			<p>
        <span>业务员</span>
        <el-input v-model="tempData.yewuyuan" class="userselect" type="text" placeholder="请输入业务员" />
      </p>
			<p>
        <span>收货客户</span>
        <el-input v-model="tempData.shouhuokehu" class="userselect" type="text" placeholder="请输入收货客户" />
      </p>
      <p>
        <span>装船日期</span>
        <el-input v-model="tempData.yujizhuangtime" class="userselect" type="text" placeholder="请输入装船日期" />
      </p>
			<p>
        <span>物料名称</span>
        <el-input v-model="tempData.wuliaoming" type="text" class="userselect" placeholder="请输入物料名称" />
      </p>
			<p>
        <span>数量</span>
        <el-input v-model="tempData.shuliang" type="number" class="userselect" placeholder="请输入数量" />
      </p>
      <p>
        <span>含税单价</span>
        <el-input v-model="tempData.hanshuidanjia" type="text" class="userselect" placeholder="请输入含税单价" />
      </p>
      <p>
        <span>价税合计</span>
        <el-input v-model="tempData.jiashuiheji" type="text" class="userselect" placeholder="请输入价税合计" />
      </p>
      <p>
        <span>佣金</span>
        <el-input v-model="tempData.yongjin" type="text" class="userselect" placeholder="请输入佣金" />
      </p>
      <p>
        <span>包装物</span>
        <el-input v-model="tempData.baozhuangwu" type="text" class="userselect" placeholder="请输入包装物" />
      </p>
      <p>
        <span>运输单价</span>
        <el-input v-model="tempData.yunshudanjia" type="text" class="userselect" placeholder="请输入运输单价" />
      </p>
      <p>
        <span>汇率</span>
        <el-input v-model="tempData.huilv" type="text" class="userselect" placeholder="请输入汇率" />
      </p>
      <p>
        <span>fob总价</span>
        <el-input v-model="tempData.fobzongjia" type="text" class="userselect" placeholder="请输入fob总价" />
      </p>
      <p>
        <span>海运费</span>
        <el-input v-model="tempData.haiyunfei" type="text" class="userselect" placeholder="请输入海运费" />
      </p>
    </div>
		<div class="submits">
		  <el-button class="save" size="small" type="primary" :loading="loading" @click="save">保存</el-button>
		  <el-button class="nosave" size="small" type="info" @click="nosave">取消</el-button>
		</div>
  </div>
</template>

<script>
import { addTiFahuo,updateTiFahuo } from '@/api/waimao'
export default {
  data(){
    return{
      tempData: {},
      loading: false,
      writeOradd: 0, //判断是0新增还是1修改
    }
  },
  mounted(){
    console.log(this.$route.params)
    if(this.$route.params.options){
      this.writeOradd = 1
      this.tempData = JSON.parse(this.$route.params.options)
    }else{
      this.writeOradd = 0
      this.tempData = {}
    }
  },
  methods:{
    /**
     * 保存发货单
     */
    save(){
      // 如果对象为空，直接返回
      if(JSON.stringify(this.tempData) === '{}'){
        this.$message({
          message: '请填写相关信息！',
          type: 'warning'
        })
        return
      }
      this.loading = true
      //0为新增操作
      if(this.writeOradd === 0){
        addTiFahuo(this.tempData).then(res => {
          console.log(res)
          this.$message({
            message: res.message,
            type: 'success'
          })
          this.$router.go(-1)
        }).catch(() => {
          this.loading = false
        })
      }else{
        // 1是编辑修改操作
        updateTiFahuo(this.tempData).then(res => {
          console.log(res)
          this.$message({
            message: res.message,
            type: 'success'
          })
          this.$router.go(-1)
        }).catch(() => {
          this.loading = false
        })
      }
      
    },
    nosave(){
      this.$router.go(-1)
    }
  }
}
</script>

<style scoped lang="scss">
  .submits {
	  display: flex;
		background: #fff;
	  padding: 20px 20px;
		border-radius: 8px;
		margin-top: 20px;
		// border-top: 1px solid #ccc;
	  justify-content: flex-end;
	  align-items: center;
	  > div {
	    width: 80px;
	    height: 32px;
	    text-align: center;
	    line-height: 32px;
	    color: #fff;
	    font-size: 14px;
	    border-radius: 4px;
	    margin-left: 30px;
	    cursor: pointer;
	  }
	  .save {
	    background: #18a05e;
	  }
	  .nosave {
	    background: #999;
	  }
	}
  .change {
	  display: flex;
	  flex-wrap: wrap;
	  background: #fff;
	  border-radius: 8px;
	  padding: 20px 0;
	  > p {
	    width: 33%;
	    font-size: 14px;
	    display: flex;
	    align-items: center;
	    color: #333;
	    /deep/.el-input__inner {
	      // width: inherit;
	      background: none;
	      height: 32px;
	      // line-height: 32px;
	      color: #333;
	      border: 1px solid rgba(0, 0, 0, 0.1);
	      padding: 0 25px;
	    }
	    /deep/.el-input__icon {
	      line-height: 32px;
	    }
	    .userselect {
	      // max-width: 250px;
	      flex: 1;
	    }
	
	    > span {
	      display: block;
	      width: 100px;
	      text-align: right;
	      padding-right: 15px;
	    }
	    > input {
	      width: inherit;
	      flex: 1;
	      height: 32px;
	      border-radius: 3px;
	      border: 1px solid rgba(0, 0, 0, 0.1);
	      padding-left: 10px;
	      color: #333;
	    }
	  }
	}
</style>